// 路由的懒加载（按需加载 有缓存）
const Login = () => import('@/pages/Login')
const Home = () => import('@/pages/Home')
const Register = () => import('@/pages/Register')
const Search = () => import('@/pages/Search')
const Details = () => import('@/pages/Detail')
const AddCartSuccess = () => import('@/pages/AddCartSuccess')
const ShopCart = () => import('@/pages/ShopCart')
const Trade = () => import('@/pages/Trade')
const Pay = () => import('@/pages/Pay')
const PaySuccess = () => import('@/pages/PaySuccess')
const Center = () => import('@/pages/Center')
const MyOrder = () => import('@/pages/Center/components/MyOrder')
const GroupOrder = () => import('@/pages/Center/components/GroupOrder')
const routes = [  // 配置路由表
	{
		path: '/Login',
		name: 'Login',
		component: Login,
		meta: {
			isHidden: true
		}
	},
	{
		path: '/Home',
		name: 'Home',
		component: Home
	},
	{
		path: '/Register',
		name: 'Register',
		component: Register,
		meta: {
			isHidden: true
		}
	},
	{
		path: '/Search/:SearchKey?',
		name: 'Search',
		component: Search,
	},
	{
		path: "/Detail/:skuId",
		component: Details,
		name: "Details",
	},
	{
		path: "/AddCartSuccess",
		component: AddCartSuccess,
		name: "AddCartSuccess",
	},
	{
		path: "/ShopCart",
		component: ShopCart,
		name: "ShopCart",
	},
	{
		path: "/Trade",
		component: Trade,
		name: "Trade",
		beforeEnter: (to, from, next) => {
			// to: 即将要进入的目标 路由对象
			// form: 当前导航正要离开的路由
			// next: 操作放行
			// 当我进Trade页面的时候 发现不是从ShopCart进入 强行跳转到ShopCart
			if (from.name !== 'ShopCart') return next('/ShopCart')
			next()
		}
	},
	{
		path: "/Pay",
		component: Pay,
		name: "Pay",
		beforeEnter: (to, from, next) => {
			// to: 即将要进入的目标 路由对象
			// form: 当前导航正要离开的路由
			// next: 操作放行
			// 当我进Pay页面的时候 发现不是从Trade进入 强行跳转到ShopCart
			if (from.name !== 'Trade') return next('/ShopCart')
			next()
		}
	},
	{
		path: "/PaySuccess",
		component: PaySuccess,
		name: "PaySuccess",
		beforeEnter: (to, from, next) => {
			// to: 即将要进入的目标 路由对象
			// form: 当前导航正要离开的路由
			// next: 操作放行
			// 当我进PaySuccess页面的时候 发现不是从Pay进入 强行跳转到ShopCart
			if (from.name !== 'Pay') return next('/ShopCart')
			next()
		}
	},
	{
		path: "/Center",
		component: Center,
		// name: "Center",
		redirect: '/Center/MyOrder',
		children: [
			{
				path: "MyOrder",
				component: MyOrder,
				name: "MyOrder",
			},
			{
				path: "GroupOrder",
				component: GroupOrder,
				name: "GroupOrder",
			},
		]
	},
	{
		path: '/',
		redirect: '/Home'
	}
]
export default routes